package de.tabuma.sso.usergroup;

import de.tabuma.sso.sso.*;
import de.tabuma.sso.group.*;
import de.tabuma.sso.user.*;

/**
 * @author $Author: alefen $
 * @version $Revision: 1.1.1.1.2.1 $
 * @since $Date: 2010/01/08 10:03:24 $
 */
public class UserGroupWebserviceLib {
    public static void userHasPrivilegForUserGroup(UserGroup userGroup, String ssoId) throws Exception {
        Group group = GroupFacade.get(userGroup.getGroupId());
        GroupWebserviceLib.userHasPrivilegForGroup(group, ssoId);
        User user = UserFacade.get(userGroup.getUserId());
        UserWebserviceLib.userHasPrivilegForUser(user, ssoId);
    }
    public static int userHasPrivileg(String ssoId) throws Exception {
        if(!SSOFacade.sessionIsActiv(ssoId)) {
            throw new Exception("Session has expired.");
        }

        int groupId = SSOFacade.userHasAdminUserPrivileg(ssoId);
        if(groupId==-1) {
            throw new Exception("User has no privileg for this action.");
        }

        return groupId;
    }
}